import axiosInstance from '../utils/axiosInstance';

// 用户管理相关API
export const adminUserApi = {
  /**
   * 获取用户列表（分页）
   * @param page 页码
   * @param size 每页大小
   * @param keyword 搜索关键字
   */
  getUsers: async (page: number = 1, size: number = 10, keyword?: string) => {
    try {
      const params: any = { page, size };
      if (keyword) {
        params.keyword = keyword;
      }
      const response = await axiosInstance.get('/admin/users', { params });
      return response.data;
    } catch (error) {
      console.error('获取用户列表失败:', error);
      throw error;
    }
  },

  /**
   * 根据ID获取用户详情
   * @param id 用户ID
   */
  getUserById: async (id: number) => {
    try {
      const response = await axiosInstance.get(`/admin/users/${id}`);
      return response.data;
    } catch (error) {
      console.error('获取用户详情失败:', error);
      throw error;
    }
  },

  /**
   * 获取用户统计信息
   */
  getUserStats: async () => {
    try {
      const response = await axiosInstance.get('/admin/users/stats');
      return response.data;
    } catch (error) {
      console.error('获取用户统计失败:', error);
      throw error;
    }
  }
};

// 数据统计相关API
export const adminStatsApi = {
  /**
   * 获取总体统计数据
   */
  getOverviewStats: async () => {
    try {
      const response = await axiosInstance.get('/admin/stats/overview');
      return response.data;
    } catch (error) {
      console.error('获取总体统计数据失败:', error);
      throw error;
    }
  },

  /**
   * 获取用户增长趋势数据
   */
  getUserGrowthStats: async () => {
    try {
      const response = await axiosInstance.get('/admin/stats/user-growth');
      return response.data;
    } catch (error) {
      console.error('获取用户增长数据失败:', error);
      throw error;
    }
  },

  /**
   * 获取收入统计数据
   */
  getRevenueStats: async () => {
    try {
      const response = await axiosInstance.get('/admin/stats/revenue');
      return response.data;
    } catch (error) {
      console.error('获取收入数据失败:', error);
      throw error;
    }
  },

  /**
   * 获取热门电影排行
   */
  getPopularMovies: async () => {
    try {
      const response = await axiosInstance.get('/admin/stats/popular-movies');
      return response.data;
    } catch (error) {
      console.error('获取热门电影数据失败:', error);
      throw error;
    }
  },

  /**
   * 获取用户分布统计
   */
  getUserDistribution: async () => {
    try {
      const response = await axiosInstance.get('/admin/stats/user-distribution');
      return response.data;
    } catch (error) {
      console.error('获取用户分布数据失败:', error);
      throw error;
    }
  }
}; 